package vip.xiaonuo.smzq.modular.synchronize.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.smzq.modular.kcl.entity.Sjgl;
import vip.xiaonuo.smzq.modular.synchronize.service.impl.ISynchDataService;

import java.util.List;

@Api(tags = "同步.mdb数据")
@RestController
@RequestMapping ("/synch/synchData")
@Validated
public class SynchDataController {

    @Autowired
    private ISynchDataService synchDataService;

    @ApiOperation("数据同步")
    @PostMapping("/tbData")
    public CommonResult<String> tbData(@ApiParam(name = "filePath",value = "文件路径") @RequestParam String filePath,
                                       @ApiParam(name = "nd",value = "年度如：2024") @RequestParam(required = false) Integer nd) {
        synchDataService.tbData(filePath,nd);
        return CommonResult.ok();
    }

    @ApiOperation("数据导出")
    @GetMapping("/dataExportMdb")
    public CommonResult<String> dataExportMdb(
            @ApiParam(name = "fileName",value = "文件名称") @RequestParam String fileName,
            @ApiParam(name = "nd",value = "年度如：2024") @RequestParam(required = false) Integer nd,
            @ApiParam(name = "tableName",value = "表格名称：2024") @RequestParam(required = false) String tableName    ) {
        synchDataService.dataExportMdb(fileName,nd,tableName);
        return CommonResult.ok();
    }
    @ApiOperation("daoshuju")
    @GetMapping("/getnow")
    public CommonResult<String> dataExportMdb( ){
        synchDataService.getnow();
        return CommonResult.ok();
    }


    /**
     * mdb文件导入
     */
    @ApiOperation("mdb文件导入")
    @PostMapping("/fileUploadMdb")
    public CommonResult<String> fileUploadMdb(
            @RequestPart("files") List<MultipartFile> files,
            @Validated Sjgl sjgl
    ) {
        return CommonResult.data(synchDataService.fileUploadMdb(files,sjgl));
    }






}
